//
//  ViewController.m
//  MasonryExample
//
//  Created by 山刘 on 2020/6/9.
//  Copyright © 2020 山刘. All rights reserved.
//

#import "ViewController.h"
#import "ExampleViewController.h"

#import "MASExampleBasicView.h"
#import "MASExampleUpdateView.h"
#import "MASExampleRemakeView.h"
#import "MASExampleConstantsView.h"
#import "MASExampleSidesView.h"
#import "MASExampleAspectFitView.h"
#import "MASExampleAnimatedView.h"
#import "MASExampleDebuggingView.h"
#import "MASExampleLabelView.h"
#import "MASExampleScrollView.h"
#import "MASExampleArrayView.h"
#import "MASExampleAttributeChainingView.h"
#import "MASExampleMarginView.h"
#import "MASExampleDistributeView.h"
#import "MASExampleRatioView.h"
#import "MASExampleTableView.h"
#import "MASExampleAutoAddView.h"
#import "MASExampleScrollHorView.h"
#import "MASExampleScrollVerView.h"
#import "MASExampleButtonAutoSizeView.h"
#import "MASExampleMulLabelAutoSizeView.h"
#import "MASExampleMulLinesView.h"
#import "MASExampleFlexView.h"
#import "MASExampleTotalUpdateAnimateView.h"
#import "MASExampleIntrinsicView.h"
#import "MASExampleTouchMoveView.h"

#import "UIKitExampleStackView.h"
#import "UIKitExampleStackViewController.h"
#import "UIKitExampleStackView02Controller.h"
#import "UIKitExampleStackViewStarController.h"


#import "MASExampleLayoutGuideViewController.h"
#import "MASExampleSafeAreaLayoutGuideViewController.h"

static NSString * const kMASCellReuseIdentifier = @"kMASCellReuseIdentifier";

@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) NSArray *exampleControllers;
@end

@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.view.backgroundColor = [UIColor whiteColor];
    [self.tableView registerClass:UITableViewCell.class forCellReuseIdentifier:kMASCellReuseIdentifier];
    
    self.exampleControllers = @[
        [[ExampleViewController alloc] initWithTitle:@"TableView" viewClass:MASExampleTableView.class],
        
        [[ExampleViewController alloc] initWithTitle:@"Basic" viewClass:MASExampleBasicView.class],
        [[ExampleViewController alloc] initWithTitle:@"Basic SubView" viewClass:UIView.class subView:MASExampleBasicView.class],
        [[ExampleViewController alloc] initWithTitle:@"Update Constraints-无效" viewClass:MASExampleUpdateView.class],
        [[ExampleViewController alloc] initWithTitle:@"Remake Constraints" viewClass:MASExampleRemakeView.class],
        [[ExampleViewController alloc] initWithTitle:@"Using Constants" viewClass:MASExampleConstantsView.class],
        
        [[ExampleViewController alloc] initWithTitle:@"Composite Edges" viewClass:MASExampleSidesView.class],
        //[[ExampleViewController alloc] initWithTitle:@"Composite Edges-Sub" viewClass:UIView.class subView:MASExampleSidesView.class],
        
        [[ExampleViewController alloc] initWithTitle:@"Aspect Fit" viewClass:MASExampleAspectFitView.class],
        [[ExampleViewController alloc] initWithTitle:@"Aspect Fit-Sub" viewClass:UIView.class subView:MASExampleAspectFitView.class],
        
        [[ExampleViewController alloc] initWithTitle:@"Basic Animated" viewClass:MASExampleAnimatedView.class],
        [[ExampleViewController alloc] initWithTitle:@"Basic Animated-Sub" viewClass:UIView.class subView:MASExampleAnimatedView.class],
        
        [[ExampleViewController alloc] initWithTitle: @"Debugging Helpers" viewClass:MASExampleDebuggingView.class],
        
        [[ExampleViewController alloc] initWithTitle:@"Bacony Labels" viewClass:MASExampleLabelView.class],
        [[ExampleViewController alloc] initWithTitle:@"Bacony Labels-Sub" viewClass:UIView.class subView:MASExampleLabelView.class],
        [[ExampleViewController alloc] initWithTitle:@"Mul Labels" viewClass:MASExampleMulLabelAutoSizeView.class],
        
        [[ExampleViewController alloc] initWithTitle:@"UIScrollView" viewClass:MASExampleScrollView.class],
        [[ExampleViewController alloc] initWithTitle:@"UIScrollView-Sub" viewClass:UIView.class subView:MASExampleScrollView.class],
        
        [[ExampleViewController alloc] initWithTitle:@"Array" viewClass:MASExampleArrayView.class],
        [[ExampleViewController alloc] initWithTitle:@"Array-Sub" viewClass:UIView.class subView:MASExampleArrayView.class],
        
        [[ExampleViewController alloc] initWithTitle:@"Attribute Chaining" viewClass:MASExampleAttributeChainingView.class],
        
        [[ExampleViewController alloc] initWithTitle:@"Margins" viewClass:MASExampleMarginView.class],
        //[[ExampleViewController alloc] initWithTitle:@"Margins-Sub" viewClass:UIView.class subView:MASExampleMarginView.class],
        
        [[ExampleViewController alloc] initWithTitle:@"Views Distribute" viewClass:MASExampleDistributeView.class],
        [[ExampleViewController alloc] initWithTitle:@"Views Distribute-Sub" viewClass:UIView.class subView:MASExampleDistributeView.class],
        [[ExampleViewController alloc] initWithTitle:@"Mul Lines View" viewClass:MASExampleMulLinesView.class],
        
        [[ExampleViewController alloc] initWithTitle:@"Ratio Views" viewClass:MASExampleRatioView.class],
        [[ExampleViewController alloc] initWithTitle:@"Ratio Views-Sub" viewClass:UIView.class subView:MASExampleRatioView.class],
        
        [[ExampleViewController alloc] initWithTitle:@"MASConstraint" viewClass:MASExampleAutoAddView.class],
        
        [[ExampleViewController alloc] initWithTitle:@"MASConstraint UIScrollView Hor" viewClass:MASExampleScrollHorView.class],
        [[ExampleViewController alloc] initWithTitle:@"MASConstraint UIScrollView Ver" viewClass:MASExampleScrollVerView.class],
        
        [[ExampleViewController alloc] initWithTitle:@"Button Auto Layout" viewClass:MASExampleButtonAutoSizeView.class],
        
        [[ExampleViewController alloc] initWithTitle:@"Flex View" viewClass:MASExampleFlexView.class],
        [[ExampleViewController alloc] initWithTitle:@"Flex View-Sub" viewClass:UIView.class subView:MASExampleFlexView.class],
        
        [[ExampleViewController alloc] initWithTitle:@"intrinsicContentSize" viewClass:MASExampleIntrinsicView.class],
        
        [[ExampleViewController alloc] initWithTitle:@"动画-更新" viewClass:MASExampleTotalUpdateAnimateView.class],
        [[ExampleViewController alloc] initWithTitle:@"动画-移动" viewClass:MASExampleTouchMoveView.class],
        
        [[ExampleViewController alloc] initWithTitle:@"UIKit-UIStackView" viewClass:UIKitExampleStackView.class],
        [[UIKitExampleStackViewController alloc] initWithNibName:@"UIKitExampleStackViewController" bundle:nil],
        [[UIKitExampleStackView02Controller alloc] init],
        [[UIKitExampleStackViewStarController alloc] init],
    ];

    
    if ([UIViewController instancesRespondToSelector:@selector(topLayoutGuide)])
    {
        self.exampleControllers = [self.exampleControllers arrayByAddingObject:[[MASExampleLayoutGuideViewController alloc] init]];
    }
    
    if ([UIView instancesRespondToSelector:@selector(safeAreaLayoutGuide)])
    {
        self.exampleControllers = [self.exampleControllers arrayByAddingObject:[[MASExampleSafeAreaLayoutGuideViewController alloc] init]];
    }
}

#pragma mark - UITableViewDataSource

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UIViewController *viewController = self.exampleControllers[indexPath.row];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kMASCellReuseIdentifier forIndexPath:indexPath];
    cell.textLabel.text = viewController.title;
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.exampleControllers.count;
}

#pragma mark - UITableViewDelegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UIViewController *viewController = self.exampleControllers[indexPath.row];
    [self.navigationController pushViewController:viewController animated:YES];
}
@end
